﻿using Microsoft.Extensions.Options;
using Microsoft.Identity.Client;

namespace FEShop.AppUserService.Configs
{

    /// <summary>
    /// 全局配置访问器
    /// </summary>
    public static class GlobalConfig
    {
        private static IServiceProvider _serviceProvider;
        private static AppUserConfig _current;

        public static AppUserConfig Current => _current ??= LoadConfig();

        public static void Initialize(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        private static AppUserConfig LoadConfig()
        {
            using var scope = _serviceProvider.CreateScope();
            var config = scope.ServiceProvider.GetRequiredService<IOptionsSnapshot<AppUserConfig>>();
            return config.Value;
        }
    }
}
